package com.example.demo.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/config")
@RestController
@RefreshScope
@Slf4j
public class OrderConfigController {

//    @Value("${order.abc}")
//    private String testData;

    @Value("${db.password}")
    private String productServiceName;

    @SentinelResource(value = "config", blockHandler = "blockHandler", fallback = "configFallback")
    @GetMapping
    public String getOrderConfig() {
        return productServiceName;
    }

    public String blockHandler() {
        return "--------- 被流控异常了 --------";
    }

    public String configFallback() {
        return "--------- 被流控 --------";
    }

}
